<?php 
//print_r($_GET);
if (isset($_GET['edit']))
{
    $loaisanpham = $_GET['loai-san-pham'];
    $sql = mysql_query("SELECT * FROM `loaisp` WHERE loaiid = $loaisanpham");
    while ($row = mysql_fetch_array($sql))
    {

?>

<form action="admin.php?module=sua-loai" method="post" enctype="multipart/form-data">
<fieldset>
    <legend><h1>Sửa loại sản phẩm</h1></legend>
  <table width="665" border="0">
    <tr>
        <td width="263">Tên loại</td>	
      <td width="386"><input type="text" name="loaisanpham" value="<?php echo $row['tenloai']; ?> "/></td>
    </tr>
      <tr>
        <td><input type="hidden" name="loaiid" value="<?php print $loaisanpham; ?> " /></td>
        <td><input class="button" type="submit" name="submit" value="Sửa" /></td>
      </tr>
    </table>
    
</fieldset>
</form>

<?php }} ?>

<?php 
//------------------------------------------------------------THEM MOI loai SAN PHAM----
    if (isset($_POST['submit']))
    {
            //print_r ($_POST);
            $loaisanpham = $_POST['loaisanpham'];
            $loaiid = $_POST['loaiid'];
            
            $sql = "update loaisp set tenloai = '$loaisanpham' where loaiid='$loaiid'";
            
            $result= mysql_query($sql);
            if ($result)
                {
                    print "<h2>Thành công!</h2><a href='admin.php?module=quan-ly-loai'><h2>Quay lại</h2></a>";
                    print "<script> alert('Thành công');
                                    window.location='admin.php?module=quan-ly-loai';</script>";                   
                }

                
    }
?>  